package com.zp2.util.code;
import java.security.SecureRandom;

public class CodeNumber {
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    private static final String CHARACTERS_NUMBER = "0123456789";


    public static String randomStringGenerator (int length){
        StringBuilder sb = new StringBuilder(length);
        SecureRandom random = new SecureRandom();

        for (int i = 0; i < length; i++) {
            //随机获取一个长度的下标
            int index = random.nextInt(CHARACTERS.length());
            sb.append(CHARACTERS.charAt(index));
        }
        return sb.toString();
    }

    public static String randomStringGeneratorNumber (int length){
        StringBuilder sb = new StringBuilder(length);
        SecureRandom random = new SecureRandom();

        for (int i = 0; i < length; i++) {
            //随机获取一个长度的下标
            int index = random.nextInt(CHARACTERS_NUMBER.length());
            sb.append(CHARACTERS_NUMBER.charAt(index));
        }
        return sb.toString();
    }
}
